﻿using Coldairarrow.Business.Backstage.TheRules;
using Coldairarrow.Entity.Backstage.TheRules;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Backstage.TheRules
{
    [Route("/Backstage/TheRules/[controller]/[action]")]
    public class BS_RebateController : BaseApiController
    {
        #region DI

        public BS_RebateController(IBS_RebateBusiness bS_RebateBus)
        {
            _bS_RebateBus = bS_RebateBus;
        }

        IBS_RebateBusiness _bS_RebateBus { get; }

        #endregion

        #region 获取

        /// <summary>
        /// 后台——获取返利列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<GetRebateDTO>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _bS_RebateBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 后台——获取返利商品列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<GetGoosDto>> GetsGoodsList(GetGoosDto input)
        {
            return await _bS_RebateBus.GetGoodsList(input);
        }

        /// <summary>
        /// 后台——获取返利详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BS_Rebate> GetTheData(IdInputDTO input)
        {
            return await _bS_RebateBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交
        /// <summary>
        /// 后台——保存返利列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BS_Rebate data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _bS_RebateBus.AddDataAsync(data);
            }
            else
            {
                await _bS_RebateBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bS_RebateBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}